package com.xnfh.home.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xnfh.framework.bean.NewVersionHelpMessageItem
import com.xnfh.framework.utils.TimeUtils
import com.xnfh.home.R
import com.xnfh.home.databinding.ItemMessageDetailBinding
import com.xnfh.image.ImageHelper
import com.xnfh.image.ImageUrl

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/10/10 4:05 PM
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/10/10 4:05 PM
 * @UpdateRemark: 更新说明
 */
class MessageDetailAdapter :
    BaseQuickAdapter<NewVersionHelpMessageItem, BaseDataBindingHolder<ItemMessageDetailBinding>>(R.layout.item_message_detail) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemMessageDetailBinding>,
        item: NewVersionHelpMessageItem
    ) {
        val dataBinding = holder.dataBinding
        //title
        holder.setText(R.id.item_message_detail_title, item.stTitle)
        //时间
        holder.setText(
            R.id.item_message_detail_data,
            TimeUtils.formatData(TimeUtils.dateFormatYMD, item.createdat)
        )
        //内容
        holder.setText(R.id.item_message_detail_message, "\t\t" + item.stText)
        //加载三张图片
        if (item.tableImgList.isNotEmpty()) {
            holder.setGone(R.id.item_message_detail_linear_img, false)
            ImageHelper.instance.loadNetImg(
                context,
                ImageUrl.BASEURL + item.tableImgList[1].compressPathUrl,
                dataBinding?.itemMessageDetailOneImg,
                com.xnfh.common.R.mipmap.image_error,
                com.xnfh.common.R.mipmap.image_error
            )
            if (item.tableImgList.size > 1) {
                ImageHelper.instance.loadNetImg(
                    context,
                    ImageUrl.BASEURL + item.tableImgList[1].compressPathUrl,
                    dataBinding?.itemMessageDetailTwoImg,
                    com.xnfh.common.R.mipmap.image_error,
                    com.xnfh.common.R.mipmap.image_error
                )
            }
            if (item.tableImgList.size > 2) {
                ImageHelper.instance.loadNetImg(
                    context,
                    ImageUrl.BASEURL + item.tableImgList[2].compressPathUrl,
                    dataBinding?.itemMessageDetailThreeImg,
                    com.xnfh.common.R.mipmap.image_error,
                    com.xnfh.common.R.mipmap.image_error
                )
            }
        } else {
            holder.setGone(R.id.item_message_detail_linear_img, true)
        }
        (holder.getView(R.id.item_message_detail_one_img) as ImageView).setOnClickListener {
        }
        (holder.getView(R.id.item_message_detail_two_img) as ImageView).setOnClickListener {
        }
        (holder.getView(R.id.item_message_detail_three_img) as ImageView).setOnClickListener {
        }
    }


}